﻿using System;
using Missbot.Service;

namespace Missbot.AIModule.Gaming.SignIn
{
    public class SignInGroupInfo : DbBaseEntity
    {
        public string GroupID { get; init; }

        public string DateStr { get; init; }

        public int IndexNo { get; set; }
    }

    public static class SignInGroupInfoDA
    {
        public static int GetAndUpdate(string GroupID)
        {
            var todayStr = DateTime.Now.ToString("yyyyMMdd");
            var rec      = MongoService<SignInGroupInfo>.GetOnly(p => p.GroupID == GroupID && p.DateStr == todayStr);
            if (rec == null)
            {
                rec = new SignInGroupInfo {GroupID = GroupID, DateStr = todayStr};
                MongoService<SignInGroupInfo>.Insert(rec);
            }

            rec.IndexNo++;
            MongoService<SignInGroupInfo>.Update(rec);

            return rec.IndexNo;
        }
    }
}